home *** CD-ROM | disk | FTP | other *** search
- Path: demigod.rutgers.edu!not-for-mail
- From: alii@demigod.rutgers.edu (Syed Ali)
- Newsgroups: comp.lang.c++
- Subject: Re: Newbie question about function calling.
- Date: 8 Mar 1996 22:24:17 -0500
- Organization: Rutgers University LCSR
- Message-ID: <4hqtl1$5os@demigod.rutgers.edu>
- References: <4hohd3$r9@brickbat.mindspring.com>
- NNTP-Posting-Host: demigod.rutgers.edu
-
-
- Although i do not see why your program is locking up, try the
- approach below. It uses less memory and should work.
-
- Why don't you change it so that the filename is a pointer to
- a string and not an array of characters? Although they sound
- the same, they are represented differently.
-
- You would therfore have in getinfo():
- char * infile;
- scanf("%s",infile);
- return(infile);
-
- Change counter to:
- int counter (char * filename);
-
- And you can then print it as:
- printf("%s",filename);
-
- Regards,
- Syed Ali
-
- ------------------------------------------------------------------
- wdnick@mindspring.com (William "Doug" Nicholson) writes:
-
- >I'm having a problem somewhere between the following two functions.
- >My main calls the function 'counter' (shown below) which in turn calls
- >'getinfo' by trying to assign 'getinfo's return value to the string
- >variable 'filename'. 'Getinfo' prompts the user to enter a filename
- >and stores it in the string 'infile'. I've added a couple of lines
- >below and started them in my post with the > so they will stand out.
- >In the first one (in the getinfo function), the printf line prints
- >whatever I type in at the prompt. Theoretically this should be passed
- >to 'filename' in the other function. Well, the printf that tries to
- >print "FILE = 'filename'" stops after "FILE =" and the computer locks
- >up.
-
- >Anybody got any idea what's happening here? Have I overlooked a
- >really stupid thing or what?
-
- >Thanks for any help. The problem area is listed below.
-
-
-
-
-
-
-
- >char getinfo(void)
- >/*****************************************************************
- > * This function prompts the user for a filename and returns it. *
- > *****************************************************************/
- >{
- > char infile[15]; /* file to process */
-
- > printf("Enter the path and filename of a file to process ");
- > printf("or enter XX to quit >");
- > scanf("%s", infile);
-
- >> printf("FILE = %s\n\n", infile);
-
- > return(infile[15]);
- >} /* end function getinfo */
-
- >int counter(void)
- >/*****************************************************************
- > * This function counts the number of times that each character *
- > * is used in a file and returns the count. *
- > *****************************************************************/
- >{
- > int i, /* lengths of triangle sides */
- > count[128]; /* character count array */
-
- > char chr,
- > filename[15] = "",
- > foo[2] = "1";
-
- > FILE *inp, /* input file pointer */
- > *outp; /* output file pointer */
-
- > filename[15] = getinfo();
-
- >> printf("FILE = %s\n\n", filename);
-
-